#!/bin/bash

ARCHIVE=live.2023.01.19.tar.gz

export CROSSPATH=/opt/yi/toolchain-sunxi-musl/toolchain/bin
export PATH=${PATH}:${CROSSPATH}

export TARGET=arm-openwrt-linux
export CROSS=arm-openwrt-linux
export BUILD=x86_64-pc-linux-gnu

export CROSSPREFIX=${CROSS}-

export STRIP=${CROSSPREFIX}strip
export CXX=${CROSSPREFIX}g++
export CC=${CROSSPREFIX}gcc
export LD=${CROSSPREFIX}ld
export AS=${CROSSPREFIX}as
export AR=${CROSSPREFIX}ar

SCRIPT_DIR=$(cd `dirname $0` && pwd)
cd $SCRIPT_DIR

rm -rf ./_install
rm -rf ./live

# live555
if [ ! -f $ARCHIVE ]; then
    wget https://download.videolan.org/pub/contrib/live555/$ARCHIVE
fi
tar zxvf $ARCHIVE
find live -type d -exec chmod 755 {} +
find live -type f -name "*.cpp" -exec chmod 644 {} +
find live -type f -name "*.hh" -exec chmod 644 {} +
find live -type f -name "Makefile*" -exec chmod 644 {} +

patch -p0 < rRTSPServer.patch

cd live || exit 1

./genMakefiles linux-cross
cp -f ../Makefile.rRTSPServer Makefile
cp -rf ../src .
cp -rf ../include .
